package com.example.lotterysystem.common.utils;


import cn.hutool.captcha.LineCaptcha;
import cn.hutool.captcha.generator.RandomGenerator;

/**
 * Created with IntelliJ IDEA.
 * Description: 生成随机验证码封装
 * User: Spider-Man
 * Date: 2025-09-09
 * Time: 17:13
 */
public class CaptchaUtil {

    /**
     * 生成随机验证码
     * @param length 验证码位数
     * @return 生成的随机验证码
     */
    public static String getCaptcha(int length) {
        //
        RandomGenerator randomGenerator = new RandomGenerator("0123456789",4);
        LineCaptcha lineCaptcha = cn.hutool.captcha.CaptchaUtil.createLineCaptcha(200,100);
        lineCaptcha.setGenerator(randomGenerator);
        //重新生成随机验证码
        lineCaptcha.createCode();
        return lineCaptcha.getCode();
    }

}
